using ASP;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Drawing;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_ProductAttributesEdit : Admin, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected TextBox TextBox_Type;
	protected DropDownList DropDownList_Type;
	protected TextBox TextBox_Name;
	protected HtmlTableRow tr1;
	protected RadioButtonList RadioButtonList_Select;
	protected HtmlTableRow tr3;
	protected RadioButtonList RadioButtonList_Methods;
	protected HtmlTableRow tr4;
	protected TextBox TextBox_Value;
	protected HtmlTableRow tr2;
	protected Repeater Repeater1;
	protected HtmlTableRow tr5;
	protected UpdatePanel UpdatePanel1;
	protected Button Button_OK;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.InitialPage();
			this.BindSpec();
		}
	}
	protected void BindSpec()
	{
		this.Repeater1.DataSource = this.conn.GetDataTable("select * from HLShop_spec");
		this.Repeater1.DataBind();
	}
	protected void InitialPage()
	{
		Shop_ProductAttributes shop_ProductAttributes = new Shop_ProductAttributes();
		string text = base.Request.QueryString["Model"].ToString();
		if (text != null)
		{
			if (!(text == "_Add"))
			{
				if (!(text == "_AddType"))
				{
					if (!(text == "_EditType"))
					{
						if (text == "_Edit")
						{
							this.tr5.Visible = false;
							this.DropDownList_Type.Visible = false;
							int id = Convert.ToInt32(base.Request.QueryString["Id"]);
							DataTable attributesById = shop_ProductAttributes.GetAttributesById(id);
							this.TextBox_Type.Text = attributesById.Rows[0]["Attributes_Type"].ToString();
							this.TextBox_Name.Text = attributesById.Rows[0]["Attributes_Name"].ToString();
							this.TextBox_Value.Text = attributesById.Rows[0]["Attributes_Value"].ToString();
							this.RadioButtonList_Methods.Items.FindByValue(attributesById.Rows[0]["Attributes_Methods"].ToString()).Selected = true;
							this.RadioButtonList_Select.Items.FindByValue(attributesById.Rows[0]["Attributes_Select"].ToString()).Selected = true;
							if (attributesById.Rows[0]["Attributes_Methods"].ToString() == "1")
							{
								this.TextBox_Value.ReadOnly = false;
								this.TextBox_Value.BackColor = Color.White;
							}
						}
					}
					else
					{
						this.TextBox_Type.ReadOnly = false;
						this.DropDownList_Type.Visible = false;
						this.tr1.Visible = false;
						this.tr2.Visible = false;
						this.tr3.Visible = false;
						this.tr4.Visible = false;
						this.TextBox_Type.BackColor = Color.Empty;
						this.TextBox_Type.Text = base.Request.QueryString["Type"].ToString();
					}
				}
				else
				{
					this.TextBox_Type.ReadOnly = false;
					this.DropDownList_Type.Visible = false;
					this.tr1.Visible = false;
					this.tr2.Visible = false;
					this.tr3.Visible = false;
					this.tr4.Visible = false;
					this.TextBox_Type.BackColor = Color.Empty;
				}
			}
			else
			{
				this.TextBox_Type.Visible = false;
				this.tr5.Visible = false;
				this.DropDownList_Type.DataSource = shop_ProductAttributes.GetAllAttributesType();
				this.DropDownList_Type.DataBind();
				this.DropDownList_Type.Items.Insert(0, new ListItem("－请选择－", ""));
				this.DropDownList_Type.Items.FindByValue(base.Request.QueryString["TypeName"].ToString()).Selected = true;
			}
		}
	}
	public bool Checkboxz(object sp_id)
	{
		bool result;
		if (base.Request.QueryString["Model"].ToString() == "_EditType")
		{
			Shop_ProductAttributes shop_ProductAttributes = new Shop_ProductAttributes();
			DataTable type_SpecByTypeName = shop_ProductAttributes.GetType_SpecByTypeName(this.TextBox_Type.Text, Convert.ToInt32(sp_id));
			if (type_SpecByTypeName != null && type_SpecByTypeName.Rows.Count != 0)
			{
				result = true;
				return result;
			}
		}
		result = false;
		return result;
	}
	protected void Button_OK_Click(object sender, EventArgs e)
	{
		Shop_ProductAttributes shop_ProductAttributes = new Shop_ProductAttributes();
		string text = base.Request.QueryString["Model"].ToString();
		if (text != null)
		{
			if (!(text == "_Add"))
			{
				if (!(text == "_Edit"))
				{
					if (!(text == "_AddType"))
					{
						if (text == "_EditType")
						{
							string text2 = base.Request.QueryString["Type"].ToString();
							if (this.TextBox_Type.Text.Trim() == "")
							{
								this.WriteErrMsg("", "商品类型名称不能为空！", "Admin_ProductAttributes.aspx");
							}
							if (!text2.Equals(this.TextBox_Type.Text.Trim()))
							{
								if (shop_ProductAttributes.GetAttributesByType(this.TextBox_Type.Text.Trim()).Rows.Count > 0)
								{
									this.WriteErrMsg("", "该商品类型名称已存在，不能重复！", "Admin_ProductAttributes.aspx");
								}
							}
							if (shop_ProductAttributes.UpdateType(this.TextBox_Type.Text.Trim(), text2))
							{
								foreach (RepeaterItem repeaterItem in this.Repeater1.Items)
								{
									HtmlInputCheckBox htmlInputCheckBox = (HtmlInputCheckBox)repeaterItem.FindControl("boxs");
									if (htmlInputCheckBox.Checked)
									{
										DataTable type_SpecByTypeName = shop_ProductAttributes.GetType_SpecByTypeName(base.Request.QueryString["Type"].ToString(), Convert.ToInt32(htmlInputCheckBox.Value));
										if (type_SpecByTypeName.Rows.Count == 0)
										{
											shop_ProductAttributes.GetAddtype_spec(this.TextBox_Type.Text.Trim(), Convert.ToInt32(htmlInputCheckBox.Value));
										}
									}
									else
									{
										shop_ProductAttributes.Getdeletetype_spec(this.TextBox_Type.Text, Convert.ToInt32(htmlInputCheckBox.Value));
									}
								}
								this.WriteSuccessMsg("", "编辑成功！", "Admin_ProductAttributes.aspx");
							}
						}
					}
					else
					{
						if (this.TextBox_Type.Text.Trim() == "")
						{
							this.WriteErrMsg("", "商品类型名称不能为空！", "");
						}
						if (shop_ProductAttributes.GetAttributesByType(this.TextBox_Type.Text.Trim()).Rows.Count > 0)
						{
							this.WriteErrMsg("", "该商品类型名称已存在，不能重复！", "");
						}
						if (shop_ProductAttributes.AddAttributes(this.TextBox_Type.Text.Trim(), this.TextBox_Name.Text.Trim(), this.TextBox_Value.Text.Trim(), "0", "0"))
						{
							foreach (RepeaterItem repeaterItem in this.Repeater1.Items)
							{
								HtmlInputCheckBox htmlInputCheckBox = (HtmlInputCheckBox)repeaterItem.FindControl("boxs");
								if (htmlInputCheckBox.Checked)
								{
									shop_ProductAttributes.GetAddtype_spec(this.TextBox_Type.Text.Trim(), Convert.ToInt32(htmlInputCheckBox.Value));
								}
							}
							this.WriteSuccessMsg("", "添加成功！", "Admin_ProductAttributes.aspx");
						}
					}
				}
				else
				{
					int id = Convert.ToInt32(base.Request.QueryString["Id"]);
					this.DropDownList_Type.Visible = false;
					if (this.TextBox_Name.Text.Trim() == "")
					{
						this.WriteErrMsg("", "商品属性名称不能为空！", "");
					}
					if (this.RadioButtonList_Methods.SelectedValue == "0" || this.RadioButtonList_Methods.SelectedValue == "2")
					{
						this.TextBox_Value.Text = "";
					}
					if (shop_ProductAttributes.UpdateAttributes(this.TextBox_Name.Text.Trim(), this.TextBox_Value.Text.Trim(), id, this.RadioButtonList_Methods.SelectedValue, this.RadioButtonList_Select.SelectedValue))
					{
						this.WriteSuccessMsg("", "编辑成功！", "Admin_ProductAttributesList.aspx?Type=" + this.TextBox_Type.Text.Trim());
					}
				}
			}
			else
			{
				if (this.DropDownList_Type.SelectedValue == "")
				{
					this.WriteErrMsg("", "商品类型名称不能为空！", "");
				}
				if (this.TextBox_Name.Text.Trim() == "")
				{
					this.WriteErrMsg("", "商品属性名称不能为空！", "");
				}
				if (this.RadioButtonList_Methods.SelectedValue == "0" || this.RadioButtonList_Methods.SelectedValue == "2")
				{
					this.TextBox_Value.Text = "";
				}
				if (shop_ProductAttributes.AddAttributes(this.DropDownList_Type.SelectedValue, this.TextBox_Name.Text.Trim(), this.TextBox_Value.Text.Trim(), this.RadioButtonList_Methods.SelectedValue, this.RadioButtonList_Select.SelectedValue))
				{
					this.WriteSuccessMsg("", "添加成功！", "Admin_ProductAttributesList.aspx?Type=" + this.DropDownList_Type.SelectedValue);
				}
			}
		}
	}
	protected void RadioButtonList_Methods_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.TextBox_Value.ReadOnly = false;
		string selectedValue = this.RadioButtonList_Methods.SelectedValue;
		if (selectedValue != null)
		{
			if (!(selectedValue == "0"))
			{
				if (!(selectedValue == "1"))
				{
					if (selectedValue == "2")
					{
						this.TextBox_Value.ReadOnly = true;
						this.TextBox_Value.BackColor = Color.LightGray;
					}
				}
				else
				{
					this.TextBox_Value.BackColor = Color.White;
				}
			}
			else
			{
				this.TextBox_Value.ReadOnly = true;
				this.TextBox_Value.BackColor = Color.LightGray;
			}
		}
	}
}
